package www.houdoudou.com.common;

import java.io.File;
import java.net.InetAddress;

public class CommonFileFunction {

	
	 public static String getPicBaseAddress(){
		 String result="";
		 
		 try {
		        String addr = InetAddress.getLocalHost().toString();
		        String ip=addr.substring(addr.lastIndexOf("/")+1);
		       // result = addr.getHostName();
		        String PicFolder="image";
		        result="http://"+ip+":8080/Houdou/"+PicFolder+"/";
		        System.out.print("PicBaseAddress==="+result);
		        System.out.print("ip==="+ip);
		    } catch (Exception e) {
		    	e.printStackTrace();
		    }
		 return result;
	 } 
	 
	 public static void deletePic(String Pic_Dir){
		 
		 String file_to_delete ="";
		 //E:\apache-tomcat-7.0.59-windows-x64\apache-tomcat-7.0.59\bin
		 String localPath= System.getProperty("user.dir");
		 String[] localPathParse= localPath.split("\\\\");
		 for(int i=0;i<localPathParse.length;i++){
	      	  System.out.println("--"+i+"---"+localPathParse[i]); 
	         } 
		 file_to_delete=localPathParse[0]+"/"+localPathParse[1]+"/"+localPathParse[2]+"/"+"webapps"+"/"+"Houdou";
		 //重写名称和目录的处理
         String[] nameparse=Pic_Dir.split("\\/");
         for(int i=0;i<nameparse.length;i++){
      	  System.out.println("--"+i+"---"+nameparse[i]); 
         } 
         
         //一级目录
         file_to_delete=file_to_delete+"/"+nameparse[4];
         File fUploadDir = new File(file_to_delete); 
         if(!fUploadDir.exists()) 
         {          
                  System.out.println(file_to_delete);                          
          }  
       //二级目录
         file_to_delete=file_to_delete+"/"+nameparse[5];
         File fUploadDir2 = new File(file_to_delete); 
         if(!fUploadDir2.exists()) 
         {             
            	  System.out.println(file_to_delete);                
          }  
         //三级目录
         file_to_delete=file_to_delete+"/"+nameparse[6];
         File fUploadDir3 = new File(file_to_delete); 
         if(!fUploadDir3.exists()) 
         {            
            	  System.out.println(file_to_delete);                      
          }  
         // 名称
         file_to_delete=file_to_delete+"/"+nameparse[7];
         File file = new File(file_to_delete);  
         // 路径为文件且不为空则进行删除  
         if (file.isFile() && file.exists()) {  
             file.delete();  
         
         }else{
        	  System.out.println(file_to_delete); 
         }  
	 }
}
